****TABLE 7****

cd "$main_dir/output/tables/main"

*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************
*COLUMNS 1-2 - GLOBAL SAMPLE********************************************************************************************************************
*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs fy_growth_rate yob_ln_gdppc)

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

//--------------------------------------------------------
//Create Table 7 (Columns 1-2)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt fy_growth_rate yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt fy_growth_rate yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zfy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_7.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
														Survey Year FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
														Generation FE, No, ///
													    Sample, Harmonized) keep(zfy_growth_rate) 	

														
//Column 2														
qui reghdfe trust_govt fy_growth_rate yob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt fy_growth_rate yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zfy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_7.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
														Survey Year FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
														Generation FE, No, ///
													    Sample, Gallup) keep(zfy_growth_rate) 


*****************************************************************************************************************************************************************
*****************************************************************************************************************************************************************
*COLUMNS 3-4 - US SAMPLE (ANES)**********************************************************************************************************************************
*****************************************************************************************************************************************************************
*****************************************************************************************************************************************************************

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table 7 (Columns 3-4)
//--------------------------------------------------------

qui reghdfe trust_fed_govt fy_growth_rate yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_fed_govt fy_growth_rate yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_fed_govt zfy_growth_rate zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_7.doc, append dec(3) nocons addtext(Geographic Unit FE, State, ///
														Survey Year FE, Yes, ///
														Survey Year FE x Survey FE, N/A, ///
														Subcontinent FE x Cohort FE, N/A, ///
														Generation FE, Yes, ///
													    Sample, ANES) keep(zfy_growth_rate) 		
		

qui reghdfe trust_fed_govt fy_growth_rate yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_fed_govt fy_growth_rate yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_fed_govt zfy_growth_rate zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_7.doc, append dec(3) nocons addtext(Geographic Unit FE, State x Survey Year, ///
														Survey Year FE, No, ///
														Survey Year FE x Survey FE, N/A, ///
														Subcontinent FE x Cohort FE, N/A, ///
														Generation FE, Yes, ///
													    Sample, ANES) keep(zfy_growth_rate)  
